import 'package:C20Driver/event/event_bus.dart';
import 'package:C20Driver/provider/order_information.dart';
import 'package:C20Driver/routers/navigator_util.dart';
import 'package:C20Driver/service/request.dart';
import 'package:C20Driver/utils/utils.dart';
import 'package:amap_map_fluttify/amap_map_fluttify.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

class CarpoolPassengerMap extends StatefulWidget {
  final String type; //0000 未接乘客 捎上乘客 ；0010 去接乘客 未到达上车点 ；0020 去送乘客未到达下车点
  final String first; //0000 初次进入捎上乘客

  CarpoolPassengerMap({this.type, this.first});
  @override
  _CarpoolPassengerMapState createState() => _CarpoolPassengerMapState();
}

class _CarpoolPassengerMapState extends State<CarpoolPassengerMap> {
  AmapController _amapController;
  var passengerType = '';
  @override
  void initState() {
    super.initState();
    passengerType = widget.type;
    eventBus.on<SetHitchRichProgress>().listen((event) {
      if (event.state == 1) {
        // 接到乘客出发
        setState(() {
          passengerType = '0020';
        });
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBody: true, //底部NavigationBar透明
      extendBodyBehindAppBar: true, //顶部Bar透明
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
      ),
      body: Container(
        child: Stack(
          children: <Widget>[
            Container(
              width: ScreenUtil().setWidth(750.0),
              height: double.infinity,
              child: Stack(
                children: <Widget>[
                  Container(
                    width: double.infinity,
                    height: ScreenUtil().setHeight(1000),
                    child: AmapView(
                      // 地图类型
                      mapType: MapType.Standard,
                      // 是否显示缩放控件
                      showZoomControl: true,
                      // 是否显示指南针控件
                      showCompass: true,
                      // 是否显示比例尺控件
                      showScaleControl: true,
                      // 是否使能缩放手势
                      zoomGesturesEnabled: true,
                      // 是否使能滚动手势
                      scrollGesturesEnabled: true,
                      // 是否使能旋转手势
                      rotateGestureEnabled: true,
                      // 是否使能倾斜手势
                      tiltGestureEnabled: true,
                      // 缩放级别
                      zoomLevel: 17.0,
                      onMapCreated: (controller) async {
                        _amapController = controller;

                        Future.delayed(Duration(milliseconds: 500), () {
                          setState(() {
                            _addMapView();
                          });
                        });
                      },
                      onMapMoveStart: (drag) async {},
                      onMapMoveEnd: (drag) async {},
                      onMarkerClicked: ((marker) async {
                        return true;
                      }),
                      onMapClicked: (latLng) {
                        return;
                      },
                    ),
                  ),
                  Positioned(
                    bottom: 0,
                    child: Offstage(
                      offstage: passengerType != '0000',
                      child: _getPassengerDetailView(),
                    ),
                  ),
                  Positioned(
                    bottom: 0,
                    child: Offstage(
                      offstage:
                          passengerType != '0010' && passengerType != '0020',
                      child: _getPassengerRountView(),
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _getPassengerRountView() {
    OrderInformation provider =
        Provider.of<OrderInformation>(context, listen: false);
    return Container(
      width: ScreenUtil().setWidth(750),
      padding: EdgeInsets.fromLTRB(
        ScreenUtil().setWidth(32),
        ScreenUtil().setWidth(40),
        ScreenUtil().setWidth(32),
        ScreenUtil().setWidth(40),
      ),
      decoration: BoxDecoration(
        color: Color(0xffffffff),
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(ScreenUtil().setWidth(40)),
          topRight: Radius.circular(ScreenUtil().setWidth(40)),
        ),
        boxShadow: <BoxShadow>[
          BoxShadow(
            color: Color(0xff999999),
          )
        ],
      ),
      child: Column(
        children: [
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Row(
                mainAxisSize: MainAxisSize.max,
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.center,
                children: [
                  Container(
                    width: ScreenUtil().setWidth(8),
                    height: ScreenUtil().setWidth(28),
                    decoration: BoxDecoration(
                      color: Color(0xff3FB956),
                      borderRadius: BorderRadius.all(
                        Radius.circular(
                          ScreenUtil().setWidth(4),
                        ),
                      ),
                    ),
                  ),
                  SizedBox(
                    width: ScreenUtil().setWidth(12),
                  ),
                  Text(
                    passengerType == '0010' ? '前往乘客上车点' : '前往乘客目的地',
                    textAlign: TextAlign.left,
                    style: TextStyle(
                        color: Color(0xff333333),
                        fontSize: ScreenUtil().setWidth(32),
                        fontWeight: FontWeight.w500),
                  ),
                ],
              ),
              SizedBox(
                height: ScreenUtil().setWidth(20),
              ),
              Text(
                '请提醒乘客系好安全带、戴好口罩',
                style: TextStyle(
                  color: Color(0xff999999),
                  fontSize: ScreenUtil().setWidth(28),
                ),
              ),
              SizedBox(
                height: ScreenUtil().setWidth(20),
              ),
              Divider(
                height: ScreenUtil().setWidth(1),
                color: Color(0xffeeeeee),
              ),
              SizedBox(
                height: ScreenUtil().setWidth(30),
              ),
            ],
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            mainAxisSize: MainAxisSize.max,
            children: [
              Text(
                '${provider.carpoolPassengerOrderInfo.departureDate}',
                style: TextStyle(
                    color: Color(0xff333333),
                    fontSize: ScreenUtil().setWidth(32),
                    fontWeight: FontWeight.w500),
              ),
              Text(
                '已付费',
                style: TextStyle(
                  color: Color(0xff3FB956),
                  fontSize: ScreenUtil().setWidth(28),
                ),
              ),
            ],
          ),
          SizedBox(
            height: ScreenUtil().setWidth(30),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              Container(
                width: provider.carpoolPassengerOrderInfo.sumCost != null &&
                        provider.carpoolPassengerOrderInfo.sumCost.length >= 6
                    ? ScreenUtil().setWidth(460)
                    : ScreenUtil().setWidth(500),
                child: Column(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Container(
                          margin: EdgeInsets.only(
                            right: ScreenUtil().setWidth(30),
                          ),
                          width: ScreenUtil().setWidth(15.0),
                          height: ScreenUtil().setWidth(15.0),
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            color: Color(0xff00BA8F),
                          ),
                        ),
                        Expanded(
                          child: Container(
                            alignment: Alignment.centerLeft,
                            child: Text(
                              '${provider.carpoolPassengerOrderInfo.depAre}',
                              style: TextStyle(
                                fontSize: ScreenUtil().setSp(30.0),
                                color: Color(0xff333333),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                    SizedBox(height: ScreenUtil().setWidth(28.0)),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Container(
                          margin: EdgeInsets.only(
                            left: ScreenUtil().setWidth(0),
                            right: ScreenUtil().setWidth(30),
                          ),
                          width: ScreenUtil().setWidth(15.0),
                          height: ScreenUtil().setWidth(15.0),
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            color: Color.fromARGB(255, 255, 102, 0),
                          ),
                        ),
                        Expanded(
                          child: Container(
                            alignment: Alignment.centerLeft,
                            child: Text(
                              '${provider.carpoolPassengerOrderInfo.destArea}',
                              style: TextStyle(
                                fontSize: ScreenUtil().setSp(30.0),
                                color: Color(0xff333333),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              RichText(
                text: TextSpan(
                  text: '￥',
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(28.0),
                    color: Color(0xff333333),
                  ),
                  children: <TextSpan>[
                    TextSpan(
                      text: '${provider.carpoolPassengerOrderInfo.sumCost}',
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(36.0),
                          color: Color(0xff333333),
                          fontWeight: FontWeight.w500),
                    ),
                  ],
                ),
              ),
            ],
          ),
          SizedBox(
            height: ScreenUtil().setWidth(30),
          ),
          Divider(
            color: Color(0xffeeeeee),
            height: ScreenUtil().setWidth(1),
          ),
          SizedBox(
            height: ScreenUtil().setWidth(30),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              ClipOval(
                child: Container(
                  width: ScreenUtil().setWidth(96.0),
                  height: ScreenUtil().setWidth(96.0),
                  child: Image.network(
                      '${provider.carpoolPassengerOrderInfo.passengerHeadimgurl}'),
                ),
              ),
              SizedBox(width: ScreenUtil().setWidth(12.0)),
              Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '${provider.carpoolPassengerOrderInfo.passengerName}',
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(28.0),
                      color: Color(0xff333333),
                    ),
                  ),
                  SizedBox(
                    height: ScreenUtil().setWidth(10),
                  ),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    mainAxisSize: MainAxisSize.min,
                    children: [
                      Container(
                        padding: EdgeInsets.fromLTRB(
                            ScreenUtil().setWidth(20),
                            ScreenUtil().setWidth(8),
                            ScreenUtil().setWidth(20),
                            ScreenUtil().setWidth(8)),
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          color: Color(0xffF6FAF6),
                          borderRadius: BorderRadius.all(
                            Radius.circular(
                              ScreenUtil().setWidth(10),
                            ),
                          ),
                        ),
                        child: Text(
                          '${provider.carpoolPassengerOrderInfo.peopleNumber}人',
                          style: TextStyle(
                              color: Color(0xff668D6E),
                              fontSize: ScreenUtil().setWidth(26),
                              fontWeight: FontWeight.w400),
                        ),
                      ),
                      SizedBox(width: ScreenUtil().setWidth(24)),
                      Container(
                        padding: EdgeInsets.fromLTRB(
                            ScreenUtil().setWidth(20),
                            ScreenUtil().setWidth(8),
                            ScreenUtil().setWidth(20),
                            ScreenUtil().setWidth(8)),
                        alignment: Alignment.center,
                        decoration: BoxDecoration(
                          color: Color(0xffF6FAF6),
                          borderRadius: BorderRadius.all(
                            Radius.circular(
                              ScreenUtil().setWidth(10),
                            ),
                          ),
                        ),
                        child: Text(
                          provider.carpoolPassengerOrderInfo.rideType == '0010'
                              ? '拼车'
                              : '独享',
                          style: TextStyle(
                              color: Color(0xff668D6E),
                              fontSize: ScreenUtil().setWidth(26),
                              fontWeight: FontWeight.w400),
                        ),
                      ),
                    ],
                  ),
                ],
              ),
              SizedBox(
                width: ScreenUtil().setWidth(120),
              ),
              InkWell(
                onTap: () => Utils.callPhone('110'),
                child: Column(
                  children: [
                    Image.asset(
                      'assets/icon/passeger110.png',
                      width: ScreenUtil().setWidth(64),
                      height: ScreenUtil().setWidth(64),
                    ),
                    SizedBox(
                      height: ScreenUtil().setWidth(10),
                    ),
                    Text(
                      '110报警',
                      style: TextStyle(
                        color: Color(0xffEC674A),
                        fontSize: ScreenUtil().setWidth(24),
                      ),
                    ),
                  ],
                ),
              ),
              SizedBox(
                width: ScreenUtil().setWidth(36),
              ),
              InkWell(
                onTap: () => Utils.callPhone(
                    provider.carpoolPassengerOrderInfo.passengerMobile),
                child: Column(
                  children: [
                    Image.asset(
                      'assets/icon/passengerPone.png',
                      width: ScreenUtil().setWidth(64),
                      height: ScreenUtil().setWidth(64),
                    ),
                    SizedBox(
                      height: ScreenUtil().setWidth(10),
                    ),
                    Text(
                      '联系乘客',
                      style: TextStyle(
                        color: Color(0xff333333),
                        fontSize: ScreenUtil().setWidth(24),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
          SizedBox(
            height: ScreenUtil().setWidth(30),
          ),
          Container(
            width: ScreenUtil().setWidth(650.0),
            height: ScreenUtil().setWidth(100.0),
            decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: [
                    Color(0xff3FB956),
                    Color(0xff65CA00),
                  ],
                ),
                borderRadius: BorderRadius.all(
                    Radius.circular(ScreenUtil().setWidth(50)))),
            child: MaterialButton(
              textColor: Colors.white,
              child: Text(
                passengerType == '0010' ? '已到达上车点' : '已到达目的地',
                style: TextStyle(
                    fontSize: ScreenUtil().setSp(32),
                    fontWeight: FontWeight.w500),
              ),
              onPressed: () {
                _receivePassenger(
                    provider.carpoolPassengerOrderInfo.orderListid);
              },
            ),
          ),
          SizedBox(
            height: ScreenUtil().setWidth(20),
          ),
        ],
      ),
    );
  }

  /// 接到乘客 || 送达乘客
  void _receivePassenger(String id) {
    String title = '';
    String quxiao = '';
    if (passengerType == '0010') {
      title = '确定已经接到乘客';
      quxiao = '还未接到';
    } else if (passengerType == '0020') {
      title = '确定已经送达乘客';
      quxiao = '还未送达';
    }
    showDialog(
        context: context,
        builder: (context) => AlertDialog(
              title: Text(title),
              actions: <Widget>[
                FlatButton(
                  child: Text(quxiao),
                  onPressed: () => Navigator.pop(context, false),
                ),
                FlatButton(
                  child: Text('确定'),
                  onPressed: () {
                    if (passengerType == '0010') {
                      Request.receivePassenger(context, id);
                    } else if (passengerType == '0020') {
                      eventBus.fire(new RefreshCarpoolPassengers(1));
                      Navigator.pop(context, false);
                      NavigatorUtil.goBack(context);
                    }
                  },
                ),
              ],
            ));
  }

  Widget _getPassengerDetailView() {
    OrderInformation provider =
        Provider.of<OrderInformation>(context, listen: false);
    return Container(
      width: ScreenUtil().setWidth(750),
      padding: EdgeInsets.fromLTRB(
        ScreenUtil().setWidth(32),
        ScreenUtil().setWidth(40),
        ScreenUtil().setWidth(32),
        ScreenUtil().setWidth(40),
      ),
      decoration: BoxDecoration(
        color: Color(0xffffffff),
        borderRadius: BorderRadius.only(
          topLeft: Radius.circular(ScreenUtil().setWidth(40)),
          topRight: Radius.circular(ScreenUtil().setWidth(40)),
        ),
        boxShadow: <BoxShadow>[
          BoxShadow(
            color: Color(0xff999999),
          )
        ],
      ),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            mainAxisSize: MainAxisSize.max,
            children: [
              Text(
                '${provider.carpoolPassengerOrderInfo.departureDate}',
                style: TextStyle(
                    color: Color(0xff333333),
                    fontSize: ScreenUtil().setWidth(32),
                    fontWeight: FontWeight.w500),
              ),
              RichText(
                text: TextSpan(
                  text: '${provider.carpoolPassengerOrderInfo.roadLevel}' + '%',
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(36.0),
                    color: Color(0xff3FB956),
                    fontWeight: FontWeight.w500,
                  ),
                  children: <TextSpan>[
                    TextSpan(
                      text: '顺路',
                      style: TextStyle(
                        fontSize: ScreenUtil().setSp(28.0),
                        color: Color(0xff3FB956),
                      ),
                    ),
                  ],
                ),
              ),
            ],
          ),
          SizedBox(
            height: ScreenUtil().setWidth(20),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            mainAxisSize: MainAxisSize.max,
            children: [
              Container(
                padding: EdgeInsets.fromLTRB(
                    ScreenUtil().setWidth(20),
                    ScreenUtil().setWidth(8),
                    ScreenUtil().setWidth(20),
                    ScreenUtil().setWidth(8)),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  color: Color(0xffF6FAF6),
                  borderRadius: BorderRadius.all(
                    Radius.circular(
                      ScreenUtil().setWidth(10),
                    ),
                  ),
                ),
                child: Text(
                  '${provider.carpoolPassengerOrderInfo.peopleNumber}人',
                  style: TextStyle(
                      color: Color(0xff668D6E),
                      fontSize: ScreenUtil().setWidth(26),
                      fontWeight: FontWeight.w400),
                ),
              ),
              SizedBox(width: ScreenUtil().setWidth(44)),
              Container(
                padding: EdgeInsets.fromLTRB(
                    ScreenUtil().setWidth(20),
                    ScreenUtil().setWidth(8),
                    ScreenUtil().setWidth(20),
                    ScreenUtil().setWidth(8)),
                alignment: Alignment.center,
                decoration: BoxDecoration(
                  color: Color(0xffF6FAF6),
                  borderRadius: BorderRadius.all(
                    Radius.circular(
                      ScreenUtil().setWidth(10),
                    ),
                  ),
                ),
                child: Text(
                  provider.carpoolPassengerOrderInfo.rideType == '0010'
                      ? '拼车'
                      : '独享',
                  style: TextStyle(
                      color: Color(0xff668D6E),
                      fontSize: ScreenUtil().setWidth(26),
                      fontWeight: FontWeight.w400),
                ),
              ),
            ],
          ),
          SizedBox(
            height: ScreenUtil().setWidth(40),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            crossAxisAlignment: CrossAxisAlignment.end,
            children: [
              Container(
                width: provider.carpoolPassengerOrderInfo.totalprice != null &&
                        provider.carpoolPassengerOrderInfo.totalprice.length >=
                            6
                    ? ScreenUtil().setWidth(460)
                    : ScreenUtil().setWidth(500),
                child: Column(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: <Widget>[
                        Container(
                          margin: EdgeInsets.only(
                            right: ScreenUtil().setWidth(30),
                          ),
                          width: ScreenUtil().setWidth(15.0),
                          height: ScreenUtil().setWidth(15.0),
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            color: Color(0xff00BA8F),
                          ),
                        ),
                        Expanded(
                          child: Container(
                            alignment: Alignment.centerLeft,
                            child: Text(
                              '${provider.carpoolPassengerOrderInfo.depAre}',
                              style: TextStyle(
                                fontSize: ScreenUtil().setSp(30.0),
                                color: Color(0xff333333),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                    SizedBox(height: ScreenUtil().setWidth(28.0)),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: <Widget>[
                        Container(
                          margin: EdgeInsets.only(
                            left: ScreenUtil().setWidth(0),
                            right: ScreenUtil().setWidth(30),
                          ),
                          width: ScreenUtil().setWidth(15.0),
                          height: ScreenUtil().setWidth(15.0),
                          decoration: BoxDecoration(
                            shape: BoxShape.circle,
                            color: Color.fromARGB(255, 255, 102, 0),
                          ),
                        ),
                        Expanded(
                          child: Container(
                            alignment: Alignment.centerLeft,
                            child: Text(
                              '${provider.carpoolPassengerOrderInfo.destArea}',
                              style: TextStyle(
                                fontSize: ScreenUtil().setSp(30.0),
                                color: Color(0xff333333),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ],
                ),
              ),
              RichText(
                text: TextSpan(
                  text: '￥',
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(28.0),
                    color: Color(0xff333333),
                  ),
                  children: <TextSpan>[
                    TextSpan(
                      text: '${provider.carpoolPassengerOrderInfo.totalprice}',
                      style: TextStyle(
                          fontSize: ScreenUtil().setSp(36.0),
                          color: Color(0xff333333),
                          fontWeight: FontWeight.w500),
                    ),
                  ],
                ),
              ),
            ],
          ),
          SizedBox(
            height: ScreenUtil().setWidth(30),
          ),
          Divider(
            color: Color(0xffeeeeee),
            height: ScreenUtil().setWidth(1),
          ),
          SizedBox(
            height: ScreenUtil().setWidth(30),
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              ClipOval(
                child: Container(
                  width: ScreenUtil().setWidth(56.0),
                  height: ScreenUtil().setWidth(56.0),
                  child: Image.network(
                      '${provider.carpoolPassengerOrderInfo.passengerHeadimgurl}'),
                ),
              ),
              SizedBox(width: ScreenUtil().setWidth(12.0)),
              Text(
                '${provider.carpoolPassengerOrderInfo.passengerName}',
                style: TextStyle(
                  fontSize: ScreenUtil().setSp(28.0),
                  color: Color(0xff333333),
                ),
              ),
            ],
          ),
          SizedBox(
            height: ScreenUtil().setWidth(30),
          ),
          Container(
            width: ScreenUtil().setWidth(650.0),
            height: ScreenUtil().setWidth(100.0),
            decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: [
                    Color(0xff3FB956),
                    Color(0xff65CA00),
                  ],
                ),
                borderRadius: BorderRadius.all(
                    Radius.circular(ScreenUtil().setWidth(50)))),
            child: MaterialButton(
              textColor: Colors.white,
              child: Text(
                '捎上乘客',
                style: TextStyle(
                    fontSize: ScreenUtil().setSp(32),
                    fontWeight: FontWeight.w500),
              ),
              onPressed: () {
                Request.driverArriveBoardingPoint(
                    cId: provider.carpoolPassengerOrderInfo.orderId,
                    sjId: provider.carpoolOrderInfo.orderId,
                    gogoBack: widget.first == '0000' ? false : true,
                    context: context);
              },
            ),
          ),
        ],
      ),
    );
  }

  _addMarkerView() {
    OrderInformation provider =
        Provider.of<OrderInformation>(context, listen: false);
    var markerList = [];
    markerList.add({
      'lat': double.parse(provider.carpoolPassengerOrderInfo.depLatitude),
      'lng': double.parse(provider.carpoolPassengerOrderInfo.depLongitude),
      'name': provider.carpoolPassengerOrderInfo.depAre,
      'image': 'assets/icon/shunfeng_qi.png'
    });
    markerList.add({
      'lat': double.parse(provider.carpoolPassengerOrderInfo.destLatitude),
      'lng': double.parse(provider.carpoolPassengerOrderInfo.destLongitude),
      'name': provider.carpoolPassengerOrderInfo.destArea,
      'image': 'assets/icon/shunfeng_zhong.png'
    });
    _amapController?.addMarkers(
      [
        for (int i = 0; i < 2; i++)
          MarkerOption(
            latLng: LatLng(markerList[i]['lat'], markerList[i]['lng']),
            widget: Container(
              child: Image.asset(
                markerList[i]['image'],
                width: ScreenUtil().setWidth(40),
                height: ScreenUtil().setWidth(50),
                fit: BoxFit.fitWidth,
              ),
            ),
            anchorV: 0.8,
            anchorU: 0.5,
            draggable: true,
          ),
      ],
    );
  }

  _addMapView() {
    OrderInformation provider =
        Provider.of<OrderInformation>(context, listen: false);
    var markerList = [];
    markerList.add({
      'lat': double.parse(provider.carpoolPassengerOrderInfo.depLatitude),
      'lng': double.parse(provider.carpoolPassengerOrderInfo.depLongitude),
      'name': provider.carpoolPassengerOrderInfo.depAre,
      'image': 'assets/icon/shunfeng_qi.png'
    });
    markerList.add({
      'lat': double.parse(provider.carpoolPassengerOrderInfo.destLatitude),
      'lng': double.parse(provider.carpoolPassengerOrderInfo.destLongitude),
      'name': provider.carpoolPassengerOrderInfo.destArea,
      'image': 'assets/icon/shunfeng_zhong.png'
    });
    // /// 两点直线距离
    _amapController?.addPolyline(PolylineOption(
      latLngList: [
        LatLng(markerList[0]['lat'], markerList[0]['lng']),
        LatLng(markerList[1]['lat'], markerList[1]['lng']),
      ],
      width: 10,
      strokeColor: Colors.green,
    ));
    List<LatLng> arr = [
      LatLng(markerList[0]['lat'], markerList[0]['lng']),
      LatLng(markerList[1]['lat'], markerList[1]['lng']),
    ];
    _amapController?.zoomToSpan(arr,
        padding: EdgeInsets.all(ScreenUtil().setWidth(0.0)));
    _addMarkerView();
  }

  @override
  void dispose() {
    _amapController.dispose();
    // _amapController = null;
    super.dispose();
  }
}
